Page tables and pages are often used in general purpose computers to facilitate accessing data in memory. FIG. 1 shows a flow diagram of accessing data in memory by mapping virtual pages to physical pages using a page table. Memory (20) is divided into physical pages representing physical addresses in memory, such as physical page 1 (22), physical page 2 (24), and physical page 3 (26). In order to enhance performance of a software application, virtual pages representing virtual memory are often used by the software application to supplement the physical memory. Thus, the number of virtual pages may be greater than the pages that represent physical memory. For example, virtual page 1 (28), virtual page 2 (30), virtual page 3 (32), virtual page 4 (34), and virtual page 5 (36) may be used by a process, even though the size of the virtual memory (represented by the virtual pages) is greater than the physical memory represented.
A page table (38) maps the virtual memory to the physical memory. For example, FIG. 1 shows virtual page 1 (28) and virtual page 2 (30) mapped onto physical page 1 (22), while virtual page 3 (22) and virtual page 4 (34) are mapped onto physical page 2 (24). Virtual page 5 (36) is mapped onto physical page 3 (26). A set of pages may be assigned to a particular software application, or to individual processes (or set of processes) executed by the software application. For example, process A of the software application may be assigned to virtual page 1 (28), and process B may be assigned to virtual page 2 (30). Thus, process A and process B share physical page 1 (22). Typically, as far as the software application is concerned, the mapping of pages through the page table is “transparent.”
FIG. 2 shows a computer system for accessing data in memory. As shown in FIG. 2, a software application (50) interacts with an operating system (52), such as Solaris™ (a trademark of Sun Microsystems), a processor (54), an external cache (an “e-cache”) (60), and the memory (20), to access a page N (62). The processor often includes such resources as an on-board cache (56), a set of registers (58).
When the software application (50) (or a process executed by the software application) requests a value of a variable stored on page N (62), the operating system (52) loads (i.e., uses a LOAD instruction) the address of the variable into a register of the set of registers (58). To accomplish the load of the value, the operating system (52) attempts to retrieve the value from the on-board cache (56). If unsuccessful, the operating system attempts to retrieve the value of the variable from the e-cache (60). If the value of the variable is still not found, the operating system (52) retrieves the value from the memory (20).
Once the value of the variable is found, the operating system (52), through a page table (not shown in FIG. 2), maps the address of the variable to a physical address in the memory (20) using the page table. Thus, the page N (62) may function as a virtual page for the software application (50), but the value of the variable is stored in a physical page in the memory (20). Page N (62), therefore, represents both a physical page and a virtual page.
Various caching schemes may be used in computer systems. For example, the e-cache (60) may be direct-mapped, where a particular address in the memory (20) is mapped to a particular cache line of a cache. For example, if the e-cache (60) is direct-mapped, the value of the variable from an address of the page N (62) may be stored in a particular cache line of the e-cache (60). Data stored in a particular page, e.g., page N (62) may be shared by two separate and distinct processes of a software application (50). For example, a software application with two different processes (e.g., a first process and a second process) maintain separate and distinct virtual pages, which are mapped to the same physical page, e.g., page N (62) In this situation, a potential corruption of data (as it relates to the second process) may result if the first process writes to page N (62).
To avoid possible corruption of data in page N (62), the operating system may use a “copy on write” memory management technique. When using copy on write, the operating system responds by copying page N to a new location (i.e., relocating the page) in the memory (20) after the first process writes to page N (62). The second process is still be mapped to the former location of page N. Other scenarios may also cause relocation of a page to a new location. For example, execution of a SET instruction for a SPARC™ processor, produced by Sun Microsystems, Inc., may cause relocation of a page.
Because the copy of page N (62) is stored in different areas of the memory (20) after such relocation, any particular data stored in the copy of page N (62), e.g., the value of the variable, may, be stored in two separate cache lines of the e-cache (60). In the case of direct-mapped e-cache (60), data from page N (60) that was previously stored in a particular line of the c-cache (60), e.g., line 100 of the e-cache (60), and was accessible by both processes from line 100, now is stored in two distinct, separate lines of the e-cache (60), e.g., line 100 and line 200 (the new line for the first process).